package thefirst.member.model;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import thefirst.support.model.HelpVO;
import thefirst.support.model.NoticeVO;
/**
 * StudentOfMemberDaoImpl
 * 	MemberDao를 implements한 클래스.
 *  회원들이면 공통적으로 가지고 있는 메서드를 
 *  학생회원에 맞게 overriding 을 진행.
 *  
 *  sqlSessionTemplate을 활용해 Data access.
 * @author kosta-00-30
 *
 */
@Repository
public class StudentOfMemberDaoImpl implements MemberDao {	
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public void registerMember(MemberVO mvo) throws SQLException {
		sqlSessionTemplate.insert("member.registerStudent",mvo);
	}

	@Override
	public MemberVO showMember(MemberVO mvo) throws SQLException {
		return sqlSessionTemplate.selectOne("member.showStudent", mvo);
	}
	@Override
	public int isExistId(MemberVO mvo) throws SQLException {	
		int result=sqlSessionTemplate.selectOne("member.isExistStuId",mvo);
		return result;
	}
	@Override
	public int updateName(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateGender(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}
	
	@Override
	public int updateTel(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateHoperegion(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public MemberVO login(MemberVO mvo) throws SQLException {
		return sqlSessionTemplate.selectOne("member.loginstudent", mvo);
	}
	/**
	 * 학생리스트를 보여주기위하여 학생회원 전체 수를 가져온다.
	 */
	@Override
	public int selectTotalMemberCount() throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.selectTotalStudentCount");
	}

	/**
	 * 해당페이지의 학생 리스트를 가져온다.
	 */
	@Override
	public List<?> getMemberListBasic(int pageNo) throws SQLException {
		return sqlSessionTemplate.selectList("member.getStudentListBasic", pageNo);
	}


	@Override
	public void withdrawalMember(MemberVO mvo) throws SQLException {
		sqlSessionTemplate.update("member.withdrawalStudent", mvo);
	}


	/**
	 * mvo로 들어온 값(name,email)으로 학생의 id를 가져온다.
	 */
	@Override
	public String findIdByNameEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findStudentIdByNameEmail", mvo);
	}
	/**
	 * 관리자의 고객 관리를 위한 List를 호출하는 메서드
	 */
	@Override
	public List<?> getListForAdmin(String pageNo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("member.getStudentListForAdmin", pageNo);
	}
	
	//페이징빈에 처리하기위한 학생리스트를 grade(고등학교1학년) 자료를 검색
	public List<?> getListStudentbyGrade(MemberSearchVO memberSearchVO) throws SQLException{		
		return sqlSessionTemplate.selectList("member.getListStudentbyGrade", memberSearchVO);
	}
	
	//페이징빈에 처리하기위한 학생리스트를 grade(고등학교1학년), 이름이 동일한 자료를 검색
	public List<?> getListStudentbyGradeAndName(MemberSearchVO memberSearchVO) throws SQLException{
		return sqlSessionTemplate.selectList("member.getListStudentbyGradeAndName", memberSearchVO);
	}

	@Override
	public MemberVO findQPassByIdEmail(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findStudentQPassByIdEmail",mvo);
	}

	@Override
	public String findPasswordByQnAPass(MemberVO mvo) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("member.findStudentPasswordByQnAPass",mvo);
	}

	@Override
	public List<?> getMyHelpList(MyHelpVO myHelpVO) throws SQLException {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("member.myHelpStudentList",myHelpVO);
	}

}
